import { EventEmitter } from 'events';

export enum WatcherEvent {
  ALL = 'all',
  FileAdded = 'FileAdded',
  FileRemoved = 'FileRemoved',
  FileChanged = 'FileChanged',
  DirectoryAdded = 'DirectoryAdded',
  DirectoryRemoved = 'DirectoryRemoved',
}
export abstract class AbstractWatcher<EventType extends string | symbol = WatcherEvent> {

  private _isPaused = false;
  private _emitter = new EventEmitter();

  protected emit(event: EventType, ...args: any[]): boolean {
    if (this._isPaused) {
      return false;
    }
    return this._emitter.emit(event, ...args);
  }

  public stop() {
    this._emitter.removeAllListeners();
  }

  public pause() {
    this._isPaused = true;
  }

  public resume() {
    this._isPaused = false;
  }

  public on(event: EventType, fn: (...args: any[]) => void): this {
    this._emitter.on(event, fn);
    return this;
  }

  public abstract start(): void;
}